package io.renren.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * @author: Mr-wang
 * @date: 2018/4/24 0024 10:12
 * @Description:
 */
@Configuration
public class StaticResourceConfig  extends WebMvcConfigurerAdapter {
    @Value("${static.path}")
    private String staticPath;
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        if(!("".equals(staticPath)) && staticPath !=null) {
            String[] appPaths=staticPath.split(",");
            for(Integer i=0;i<appPaths.length;i++){
                String[] appNames=appPaths[i].split("=");
                String appName=appNames[0];
                String appPath=appNames[1];
                registry.addResourceHandler(appName+"**").addResourceLocations(appPath);
            }
        }
        super.addResourceHandlers(registry);
    }
}